var wxpay = require('../../utils/pay.js')
var app = getApp();
var _openid = app.getOpenId();
Page({
  data:{
    WithDrawalAmount:"",  //提现金额
    name:"",  //姓名
    creditCardNumbers:"",  //银行卡号
    openingBank:"",   //开户行
  },
 
  onLoad:function(options){
    // 生命周期函数--监听页面加载
   
  },
  onReady:function(){
    // 生命周期函数--监听页面初次渲染完成
 
  },
 
  onShow:function(){
    // 获取订单列表
    // wx.showLoading();

    var that = this;
    var postData = {
      token: app.globalData.token
    };
    postData.status = that.data.currentType;
    wx.request({
      
      url: app.globalData.domain + app.globalData.subDomain +'/my/balance?',
      method: 'post',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        openid:_openid
      },
      success: (res) => {

        var balances = [];
        var walletBalance;
        // wx.hideLoading();
        if (res.data.code == 100) {
          that.setData({
            walletBalance: res.data.obj.balance
          });
          console.log('钱包余额' +  this.balances);
        } else {
          var tip = res.data.message;
          wx.showToast({
            title: tip,
            icon: 'failure',
            duration: 2000
          })
        }
      }
    }) 
  },

  //提现金额
  WithDrawalAmountInput:function(e){
      this.data({
        WithDrawalAmount: e.detail.value
      })
  },

  //金额
  nameInput: function(e){
      this.data({
        name:e.detail.value  
      })
  },

  //银行卡号
  creditCardNumbersInput:function(e){
      this.data({
        creditCardNumbers:e.detail.value
      })
  },

  //开户行
  openingBankInput:function(e){
      this.data({
        openingBank:e.detail.value
      })
  },

  //申请提现
  withDrawDeposit: function (){
    wx.request({
      url: 'https://yjy.beichenhuayu.com/tuikeService/m/api/my/applyCash?',
      method: 'post',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        openid: _openid,
        amount:this.data.WithDrawalAmount,
        realName:this.data.name,
        bankName:this.data.creditCardNumbers,
        bankNumber:this.data.openingBank,
      },
      success: (res) => {
        // wx.hideLoading();
        if (res.data.code == 100) {
          wx.showToast({
            title: '提现成功',
            icon: 'success',
            duration: 2000
          })
        } else {
          var tip = "操作失败" + res.data.message;
          wx.showModal({
            title: '提示',
            content: tip,
            success: function (res) {
              if (res.confirm) {
                console.log('用户点击确定')
              } else if (res.cancel) {
                console.log('用户点击取消')
              }
            }
          })
        }
      }
    })
  },














  onHide:function(){
    // 生命周期函数--监听页面隐藏
 
  },
  onUnload:function(){
    // 生命周期函数--监听页面卸载
 
  },
  onPullDownRefresh: function() {
    // 页面相关事件处理函数--监听用户下拉动作
   
  },
  onReachBottom: function() {
    // 页面上拉触底事件的处理函数
  
  }
})
